package com.example.offer;

/**
 * 70. ???
 * ??????????? n ?????????
 * <p>
 * ?????? 1 ? 2 ??????????????????????
 * <p>
 * ????? n ???????
 * <p>
 * ?? 1?
 * <p>
 * ??? 2
 * ??? 2
 * ??? ????????????
 * 1.  1 ? + 1 ?
 * 2.  2 ?
 * ?? 2?
 * <p>
 * ??? 3
 * ??? 3
 * ??? ????????????
 * 1.  1 ? + 1 ? + 1 ?
 * 2.  1 ? + 2 ?
 * 3.  2 ? + 1 ?
 */
public class ClimbStairs {
    public int climbStairs(int n) {
        if (n == 1) return 1;
        int a = 1;
        int b = 2;
        for (int i = 3; i <= n; i++) {
            int sum = a + b;
            a = b;
            b = sum;
        }
        return b;
    }
}
